package utils

import (
	"github.com/gofiber/fiber/v2"
	"github.com/mojocn/base64Captcha"

)

type CaptchaResult struct {
	Id            string	`json:"id"`
	CaptchaType   string	`json:"captcha_type"`
	VerifyValue   string	`json:"code"`
}
var store = base64Captcha.DefaultMemStore
// 生成验证码
func GenerateCaptcha(ctx *fiber.Ctx) error{
	var driver= base64Captcha.DefaultDriverDigit
	captcha := base64Captcha.NewCaptcha(driver, store)
	id, base64s, err := captcha.Generate()
	body := map[string]interface{}{"coderurl": base64s, "captchaId": id, "msg": "success"}
	if err!=nil{
		body = map[string]interface{}{"msg": err.Error()}
	}
	return Success(ctx,body)

}

func VerifyCaptcha(id string,value string)bool{
	//body := map[string]interface{}{"code": 0, "msg": "failed"}
	//if store.Verify(id, value, true) {
	//	body = map[string]interface{}{"code": 1, "msg": "ok"}
	//}
	return store.Verify(id, value, true)
}